﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using JTicket.Common;
using System.Data;
using JTicket.DAL;
namespace JTicket.UI
{
    public partial class S_BookTickekt : System.Web.UI.Page
    {
       private readonly BLL.D_OperInfo bllOper = new BLL.D_OperInfo();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        void Bind()
        {
            this.txtBeginTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            this.txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            DataSet ds = DAL.H_BookInfo.P_Select(btime, etime, "", "", "预留场次");
            this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
            this.DropDownList1.DataTextField = ds.Tables[0].Columns["title"].ToString();
            this.DropDownList1.DataValueField = ds.Tables[0].Columns["titlecode"].ToString();
            this.DropDownList1.DataBind();
        }
        protected void txtEndTime_TextChanged(object sender, EventArgs e)
        {

            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            DataSet ds = DAL.H_BookInfo.P_Select(btime, etime, "", "", "预留场次");
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
                this.DropDownList1.DataTextField = ds.Tables[0].Columns["title"].ToString();
                this.DropDownList1.DataValueField = ds.Tables[0].Columns["titlecode"].ToString();
                this.DropDownList1.DataBind();
                this.DropDownList1.Items.Insert(0, new ListItem("所有"));
            }
        }
        protected void dg1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemIndex == -1) return;
            e.Item.Attributes.Add("bgcolor", "#EFFFDA");
            e.Item.Attributes.Add("style", "cursor:hand");
            e.Item.Attributes.Add("onMouseOver=this.style.backgroundColor", "#DBE3FA");
            e.Item.Attributes.Add("onMouseOut=this.style.backgroundColor", "#F6F6F6");
            e.Item.Attributes.Add("ondblclick", "window.showModalDialog('S_BookList.aspx?ordercode=" + e.Item.Cells[1].Text + "&usertel=" + e.Item.Cells[3].Text + "&usertext=" + e.Item.Cells[2].Text + "','','location:No;status:No;help:No;dialogWidth:900px;dialogHeight:500px;scroll:no');");

        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            if (this.DropDownList1.Items.Count > 0)
            {
                DataSet ds = DAL.H_BookInfo.P_Select(this.txtBeginTime.Text, this.txtEndTime.Text, DropDownList1.SelectedItem.Value, bllOper.Oper().ThCode, "预留订单");

                this.dg1.DataSource = ds.Tables[0].DefaultView;
                this.dg1.DataBind();
            }
            else
            {
                JsMsg.Alert("请选择演出名称");

            }

        }

        protected void txtBeginTime_TextChanged(object sender, EventArgs e)
        {
            string btime = this.txtBeginTime.Text;
            string etime = this.txtEndTime.Text;
            DataSet ds = DAL.H_BookInfo.P_Select(btime, etime, "", "", "预留场次");
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
                this.DropDownList1.DataTextField = ds.Tables[0].Columns["Stitlename"].ToString();
                this.DropDownList1.DataValueField = ds.Tables[0].Columns["StitleCode"].ToString();
                this.DropDownList1.DataBind();
                this.DropDownList1.Items.Insert(0, new ListItem("所有"));
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (dg1.Items.Count > 0)
            {
                bool b = false;
                for (int i = 0; i <= dg1.Items.Count - 1; i++)
                {
                    CheckBox cb = (CheckBox)dg1.Items[i].Cells[0].FindControl("CheckBox1");
                    if (cb.Checked)
                    {
                        Model.SaleParm sale = new Model.SaleParm();
                        sale.TitleCode = cb.ToolTip;
                        sale.UserName = dg1.Items[i].Cells[2].Text;
                        sale.UserTel = dg1.Items[i].Cells[3].Text;
                        sale.ThCode = bllOper.Oper().ThCode;
                        b = H_OrderBal.OrderBookTicket(sale, bllOper.Oper().OperCode,
                            Request.UserHostAddress, "",
                            dg1.Items[i].Cells[1].Text, "", "", "预留解锁");
                    }
                }
                if (b)
                {
                    JsMsg.Alert("操作成功!");
                }
                DataSet ds = DAL.H_BookInfo.P_Select(this.txtBeginTime.Text, this.txtEndTime.Text, DropDownList1.SelectedItem.Value, bllOper.Oper().ThCode, "预留订单");
                this.dg1.DataSource = ds.Tables[0].DefaultView;
                this.dg1.DataBind();
            }
            else
            {
                JsMsg.Alert("无记录!");
            }
        }
    }
}